import Vue from 'vue'
import Router from 'vue-router'
import constantRouterMap from './routes'
import interceptor from './interceptor'
import NProgress from 'nprogress' // Progress 进度条
import 'nprogress/nprogress.css'// Progress 进度条样式
// in development-env not use lazy-loading, because lazy-loading too many pages will cause webpack hot update too slow. so only in production use lazy-loading;
// detail: https://panjiachen.github.io/vue-element-admin-site/#/lazy-loading

Vue.use(Router)

const router = new Router({
  // mode: 'history', //后端支持可开
  scrollBehavior(to, from, savedPosition) {
    if (savedPosition) {
      return savedPosition
    } else {
      return {x: 0, y: 0}
    }
  },
  routes: constantRouterMap
})
router.beforeEach((to, from, next) => {NProgress.start(); next()}) //开始进度条
interceptor(router)// 拦截器
router.afterEach(() => NProgress.done()) // 结束进度条
window.router= router
export default router
